package com.taobao.classloader.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taobao.classloader.ClassLoadStrategy;
import com.taobao.classloader.JarClassLoader;

public class ChildPriorLoadStrategy implements ClassLoadStrategy {
	private static Logger	logger	= LoggerFactory.getLogger(ChildPriorLoadStrategy.class);

	@Override
	public Class<?> loadClass(String className, JarClassLoader jarClassLoader, ClassLoader parentClassLoader) {
		Class<?> clazz = jarClassLoader.loadClassFromResource(className);
		if (clazz == null) {
			try {
				clazz = parentClassLoader.loadClass(className);
			} catch (ClassNotFoundException e) {
				logger.debug("Can't load class:{} from parent classLoader.", className);
			}
		}
		return clazz;
	}

	@Override
	public String toString() {
		return "ChildPriorLoadStrategy";
	}
}
